package com.cow.controller;

import com.cow.entity.ProductType;
import com.cow.service.ProductTypeService;
import com.cow.util.general.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/productType")
public class ProductTypeController {

    @Autowired
    private ProductTypeService productTypeService;

    @GetMapping("/findAllName")
    public CommonResult findAllName(){
       List<String> typeNames = productTypeService.list()
               .stream()
               .map(ProductType::getTypeName)
               .collect(Collectors.toList());
       return CommonResult.success("分类名称查询成功",typeNames);
    }


    @GetMapping("/findAll")
    public CommonResult findAll(){
       List<ProductType> typeList = productTypeService.list();
       return CommonResult.success("分类列表查询成功",typeList);
    }


}
